#pragma once
/*
* 1: friend class Singleton<MySingleton>;
* 2: private constructor
class MySingleton : public Singleton<MySingleton> {
    friend class Singleton<MySingleton>;
    MySingleton() = default;
public:
};
*/

template <typename T> class Singleton {
protected:
  static T *instance;
  Singleton() {}
  virtual ~Singleton() {}

public:
  static T *get() {
    if (!instance) {
      instance = new T();
    }
    return instance;
  }
};

template <typename T> T *Singleton<T>::instance = nullptr;
